package com.tql;

import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

public class TestHash {
    public static void main(String[] args) {
        System.out.println("存放结构化数据，如用户信息");
        Jedis jedis=new Jedis("127.0.0.1",6379);
        jedis.flushDB();
        Map<String ,String> map=new HashMap<>();
        map.put("key1","value1");
        map.put("key2","value2");
        map.put("key3","value3");
        //添加名称我hash的元素
        jedis.hmset("hash",map);
        jedis.hset("hash","key4","4");
        System.out.println("散列hash的所欲键值对"+jedis.hgetAll("hash"));
        System.out.println("散列hash的所有键"+jedis.hkeys("hash"));
        System.out.println("散列哈市的所有值"+jedis.hvals("hash"));
        System.out.println("散列hash 添加一个证书，如果key5不存在，添加key5"+jedis.hincrBy("hash","key4",6));
        System.out.println("查看"+jedis.hgetAll("hash"));
        System.out.println(jedis.hincrBy("hash","key5",6));
        System.out.println("删除一个或多个键值对"+jedis.hdel("hash","key3","key5"));
        System.out.println(jedis.hgetAll("hash"));
        System.out.println("键值对长度"+jedis.hlen("hash"));
        System.out.println("获取多个值"+jedis.hmget("hash","key2","key3"));
    }
}
